package com.uchengwang.ui.utils;

import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;

/**
 * Created by U城网 on 2018/1/24.
 */

public class ChangeTextColorUtils {

    private static ChangeTextColorUtils utils;
    private ChangeTextColorUtils (){}

    public static ChangeTextColorUtils getUtils() {
        if (utils == null){
            utils = new ChangeTextColorUtils();
        }
        return utils;
    }

    //改变部分字体的颜色
    public SpannableStringBuilder changeColor(int color, String content, int firstIndex, int lastIndex){
        //部分文字改变颜色
        //ForegroundColorSpan 为文字前景色，BackgroundColorSpan为文字背景色
        ForegroundColorSpan redSpan = new ForegroundColorSpan(color);
        SpannableStringBuilder builder = new SpannableStringBuilder(content);
        builder.setSpan(redSpan, firstIndex, lastIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return builder;
    }
}
